package fw_utils

import (
	"bytes"
	"crypto/rand"
	"math/big"
	"time"
)

type RANDOM_TYPE int

const (
	CHAR_DIGITAL RANDOM_TYPE = 0
	CHAR_ONLY    RANDOM_TYPE = 1
	DIGITAL_ONLY RANDOM_TYPE = 2
	UPPER_ONLY   RANDOM_TYPE = 3
	LOWER_ONLY   RANDOM_TYPE = 4
)

func RandomString(len int, randomType RANDOM_TYPE) string {
	var container string
	var str string
	switch randomType {
	case CHAR_DIGITAL:
		str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
	case CHAR_ONLY:
		str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
	case DIGITAL_ONLY:
		str = "0123456789"
	case UPPER_ONLY:
		str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
	case LOWER_ONLY:
		str = "abcdefghijklmnopqrstuvwxyz0123456789"
	default:
		str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
	}
	b := bytes.NewBufferString(str)
	length := b.Len()
	bigInt := big.NewInt(int64(length))
	for i := 0; i < len; i++ {
		randomInt, _ := rand.Int(rand.Reader, bigInt)
		container += string(str[randomInt.Int64()])
	}
	return container
}

func BizCode() string {
	return "BIZ" + time.Now().Format("20060102150405") + RandomString(4, UPPER_ONLY)
}
func PrintCode() string {
	return "TPL" + RandomString(4, CHAR_DIGITAL)
}
func OssRand() string {
	return RandomString(4, CHAR_DIGITAL)
}
